package com.ruoyi.web.controller.sxt;

import java.util.List;
import javax.servlet.http.HttpServletResponse;


import com.ruoyi.common.core.domain.entity.SxtJuese;
import com.ruoyi.sxt.domain.SxtYonghu;
import com.ruoyi.sxt.domain.SxtYonghuJuese;
import com.ruoyi.sxt.service.ISxtJueseService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 角色信息Controller
 * 
 * @author ruoyi
 * @date 2025-04-18
 */
@RestController
@RequestMapping("/sxt/juese")
public class SxtJueseController extends BaseController
{
    @Autowired
    private ISxtJueseService sxtJueseService;

    /**
     * 查询角色信息列表
     */
    @PreAuthorize("@ss.hasPermi('sxt:juese:list')")
    @GetMapping("/list")
    public TableDataInfo list(SxtJuese sxtJuese)
    {
        startPage();
        List<SxtJuese> list = sxtJueseService.selectSxtJueseList(sxtJuese);
        return getDataTable(list);
    }

    /**
     * 查询某角色绑定的用户列表
     */
    @PreAuthorize("@ss.hasPermi('sxt:juese:list')")
    @GetMapping("/juese_yonghu_list")
    public TableDataInfo jueseYonghuList(SxtYonghu sxtYonghu)
    {
        startPage();
        List<SxtYonghu> jueseYonghulist = sxtJueseService.allocatedYonghuList(sxtYonghu);
        return getDataTable(jueseYonghulist);
    }

    /**
     * 查询某角色绑定的剩余用户列表
     */
    @PreAuthorize("@ss.hasPermi('sxt:juese:list')")
    @GetMapping("/shengyu")
    public TableDataInfo jueseYonghuShengyuList(SxtYonghu sxtYonghu)
    {
        List<SxtYonghu> jueseYonghuShengyulist = sxtJueseService.notAllocatedYonghuList(sxtYonghu);
        return getDataTable(jueseYonghuShengyulist);
    }

    /**
     * 查询某角色绑定的剩余用户列表
     */
    @PreAuthorize("@ss.hasPermi('sxt:juese:list')")
    @GetMapping("/fen_pei_yong_hu")
    public AjaxResult insertYonghuJueseList(SxtYonghuJuese sxtYonghuJuese)
    {
        return toAjax(sxtJueseService.insertSxtYonghuJuese(sxtYonghuJuese.getRoleId(), sxtYonghuJuese.getIds1()));
    }

    /**
     * 导出角色信息列表
     */
    @PreAuthorize("@ss.hasPermi('sxt:juese:export')")
    @Log(title = "角色信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SxtJuese sxtJuese)
    {
        List<SxtJuese> list = sxtJueseService.selectSxtJueseList(sxtJuese);
        ExcelUtil<SxtJuese> util = new ExcelUtil<SxtJuese>(SxtJuese.class);
        util.exportExcel(response, list, "角色信息数据");
    }

    /**
     * 获取角色信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('sxt:juese:query')")
    @GetMapping(value = "/{roleId}")
    public AjaxResult getInfo(@PathVariable("roleId") Long roleId)
    {
        return success(sxtJueseService.selectSxtJueseByRoleId(roleId));
    }

    /**
     * 新增角色信息
     */
    @PreAuthorize("@ss.hasPermi('sxt:juese:add')")
    @Log(title = "角色信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SxtJuese sxtJuese)
    {
        return toAjax(sxtJueseService.insertSxtJuese(sxtJuese));
    }

    /**
     * 修改角色信息
     */
    @PreAuthorize("@ss.hasPermi('sxt:juese:edit')")
    @Log(title = "角色信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SxtJuese sxtJuese)
    {
        return toAjax(sxtJueseService.updateSxtJuese(sxtJuese));
    }

    /**
     * 删除角色信息
     */
    @PreAuthorize("@ss.hasPermi('sxt:juese:remove')")
    @Log(title = "角色信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{roleIds}")
    public AjaxResult remove(@PathVariable Long[] roleIds)
    {
        return toAjax(sxtJueseService.deleteSxtJueseByRoleIds(roleIds));
    }

    /**
     * 批量删除用户角色信息
     */

    @PutMapping("/authUser/cancelAll")
    public AjaxResult deleteAuthUsers(Long roleId, Long[] userIds)
    {
        return toAjax(sxtJueseService.deleteAuthUsers(roleId, userIds));
    }

    /**
     * 删除用户角色信息
     */
    @PutMapping("/authUser/cancel")
    public AjaxResult deleteAuthUser(@RequestBody SxtYonghuJuese sxtYonghuJuese)
    {
        return toAjax(sxtJueseService.deleteAuthUser(sxtYonghuJuese));
    }
}
